package cn.cxy.demo

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.contentTv
import kotlinx.android.synthetic.main.activity_main2.*
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class MainActivity2 : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main2)
        queryData()
    }

private fun queryData() {
    val networkService = getNetworkService()
    val call = networkService.query()
    call.enqueue(object : Callback<Task?> {
        override fun onResponse(call: Call<Task?>?, response: Response<Task?>) {
            val bean: Task? = response.body()
            contentTv.text = bean?.name
            queryData2()
        }

        override fun onFailure(call: Call<Task?>?, t: Throwable) {
            Log.e("MainActivity", "网络请求失败:" + t.message)
        }
    })
}

private fun queryData2() {
    val networkService = getNetworkService()
    val call = networkService.query2()
    call.enqueue(object : Callback<Task?> {
        override fun onResponse(call: Call<Task?>?, response: Response<Task?>) {
            val bean: Task? = response.body()
            contentTv2.text = bean?.name
        }

        override fun onFailure(call: Call<Task?>?, t: Throwable) {
            Log.e("MainActivity", "网络请求失败:" + t.message)
        }
    })
}
}
